package com.lixin.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lixin.springcloud.entities.CommonResult;
import com.lixin.springcloud.entities.Payment;
import com.lixin.springcloud.myhandler.CustomerBlockHandler;
import com.lixin.springcloud.myhandler.CustomerFallbackHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomerHandlerController {

    @GetMapping("/customerHandler/{id}")
    @SentinelResource(
            value = "myCustomerHandler",
            blockHandlerClass = {CustomerBlockHandler.class},
            blockHandler = "handlerException2",
            fallbackClass = {CustomerFallbackHandler.class},
            fallback = "handlerException1"
    )
    public CommonResult<Payment> customerHandler(@PathVariable("id") Long id) {
        if (id != 666L) {
            throw new IllegalArgumentException("非法ID");
        }
        return new CommonResult<>(20000, "未发生任何异常，success", new Payment(id, "NO20210407120156L343"));
    }

}
